<template>
    <div id="adupdate">
        <g-admin></g-admin>
        <el-form style="width: 100px;height: 100px;margin: 0 auto" :model="ruleForm">
            <el-form-item label="用户名" prop="userName">
                <el-input v-model="ruleForm.userName"></el-input>
            </el-form-item>
            <el-form-item label="信誉分" prop="userGrade">
                <el-input v-model="ruleForm.userGrade"></el-input>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="submitForm">修改</el-button>
            </el-form-item>



        </el-form>
    </div>
</template>

<script>
    import GAdmin from '../../components/gadmin/GAdmin';
    import axios from 'axios';
    export default {
        components: {
            GAdmin
        },
        name: "adupdate",
        created(){
            this.ruleForm.userName = this.$route.query.userName;
            this.requestForMessage(this.ruleForm.userName);
        },
        data() {
            return {
                ruleForm: {
                    userName: '',
                    userGrade: ''
                },
                rules: {
                    userName: [
                        {required: true, message: '用户名不能为空', trigger: 'blur'}
                    ],
                    userGrade: [
                        {required: true, message: '信誉分修改不能为空', trigger: 'blur'}
                    ]
                }
            };
        },
        mounted(){
            document.querySelector('.tabbar').setAttribute('style','display:none');
            document.querySelector('.gfooter').setAttribute('style','display:none');
        },
        methods: {
            requestForMessage(userName){
                //获取user内容
                this.request({
                    url:'/user/finduser/'+userName
                }).then(res=>{
                    this.ruleForm = res.data;
                }).catch(err=>{
                    console.log(err);
                });
            },

            submitForm() {
                let url = 'http://localhost:8080/user/update';
                axios.post(url, this.ruleForm).then(
                    res => {
                        alert("修改成功！");
                        location.reload(true);
                        console.log(res.data);
                    }
                ).catch(err => {
                    console.log(err);
                })

            }

        }
    }
</script>

<style scoped>

    #adupdate{
        width: 90%;
        margin-left: 10%;
        margin-top: 40px;
        background-color: #eaffea;
    }

</style>